package xyz.xtt.pay.service;

import java.math.BigDecimal;

import xyz.xtt.pay.api.enums.PayOrderBusinessTypeEnum;
import xyz.xtt.pay.client.request.MakeOrderRequest;
import xyz.xtt.pay.entity.TblBusinessOrder;

/**
 * 订单操作API
 */
public interface BusinessOrderOperator {
	/**
	 * 是否支持该类型的订单
	 *
	 * @param type
	 * @return
	 */
	boolean canOperateType(PayOrderBusinessTypeEnum type);

	/**
	 * 创建订单
	 *
	 * @param uid              用户ID
	 * @param makeOrderRequest 创建订单请求
	 * @return 订单
	 */
	TblBusinessOrder makeOrder(String uid, MakeOrderRequest makeOrderRequest);

	/**
	 * 计算订单总价
	 *
	 * @param order 订单
	 * @return 订单总价 实际单价*数量+运费-优惠金额
	 */
	default BigDecimal calculateOrderTotalPrice(TblBusinessOrder order) {
		return (order.getRealPrice().multiply(new BigDecimal(order.getPurchaseNum()))).add(order.getTransportPrice()).subtract(order.getDiscountAmount());
	}

}
